import { OpenAIEmbeddings } from "@langchain/openai";

export const useEmbeddings = () => {
    const embeddings = new OpenAIEmbeddings({
        apiKey: process.env.DASHSCOPE_API_KEY,
        model: "text-embedding-v1", // 阿里云的 embedding 模型
        batchSize: 25, // 阿里云限制每次最多处理 25 个文档
        configuration: {
          baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1",
        },
      });
    return embeddings
}
export const convertDocsToString = (documents: any[]): string => {
    return documents.map((document) =>  document.pageContent).join("\n")
}